package com.ddtech.business.train.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ddtech.annotation.AnonymousAccess;
import com.ddtech.business.train.entity.TrainGrade;
import com.ddtech.business.train.query.TrainGradeQuery;
import com.ddtech.business.train.service.TrainGradeService;
import com.ddtech.framework.log.aop.log.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @version v1.0
 * @ClassName:TrainGradeController description：
 * @author:wei_zhang(xiao)
 * @date: 2023-12-26 20:47
 */
@Api(tags = "VR-成绩训练")
@RestController
@RequestMapping("/train-grade")
public class TrainGradeController {

    @Autowired
    private TrainGradeService trainGradeService;

    @Log("保存训练数据")
    @ApiOperation(value = "保存训练数据")
    @PostMapping(value = "/create")
    @AnonymousAccess
    public ResponseEntity create(@RequestBody TrainGrade trainGrade) {
        trainGradeService.create(trainGrade);
        return new ResponseEntity(true,HttpStatus.OK);
    }

    @Log("绑定用户，获取用户训练数据")
    @ApiOperation(value = "绑定用户，获取用户训练数据")
    @GetMapping(value = "/bind_user/{account}")
    @AnonymousAccess
    public ResponseEntity bingUser(@PathVariable  String account) {
        return new ResponseEntity(trainGradeService.bindUser(account),HttpStatus.OK);
    }

    @ApiOperation(value = "用户训练数据查询")
    @GetMapping(value = "/findGrade")
    @AnonymousAccess
    public ResponseEntity findGrade(TrainGradeQuery trainGradeQuery) {
        return new ResponseEntity(trainGradeService.findGrade(trainGradeQuery),HttpStatus.OK);
    }

    @ApiOperation(value = "用户训练数据查询")
    @GetMapping(value = "/vrGrade")
    @AnonymousAccess
    public ResponseEntity findVrGrade(TrainGradeQuery trainGradeQuery) {
        return new ResponseEntity(trainGradeService.findVrGrade(trainGradeQuery),HttpStatus.OK);
    }

    @ApiOperation(value = "用户训练数据查询")
    @GetMapping(value = "/vrUserGrade")
    @AnonymousAccess
    public ResponseEntity findVrUserGrade(@RequestParam @ApiParam("页码") int page,
                                          @RequestParam @ApiParam("页面大小") int size,
                                          String startTime,
                                          String endTime) {
        IPage pageableRequest = new Page(page + 1, size);
        return new ResponseEntity(trainGradeService.findVrUserGrade(pageableRequest,startTime,endTime),HttpStatus.OK);
    }

}
